<?php

require_once 'amfcms/ask/model/common.inc.php';
$conn = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd) or die("<script>alert('数据库服务器或登录密码无效，\\n\\n无法连接数据库，请重新设定！');history.go(-1);</script>");
mysql_select_db($cfg_dbname) or die("<script>alert('选择数据库失败，可能是你没权限，请预先创建一个数据库！');history.go(-1);</script>");
mysql_query("SET NAMES '".$cfg_db_language."',character_set_client=binary,sql_mode='';",$conn);

function installdata($datafilename){
	$fp = fopen(dirname(__FILE__).'/'.$datafilename,'r');
    while(!feof($fp))
    {
		$line = rtrim(fgets($fp,1024));
		if(preg_match("#;$#", $line))
        {
			$query .= $line;
			$rs = mysql_query($query,$conn);
			print mysql_error();
			$query='';
        } else if(!preg_match("#^(\/\/|--)#", $line))
        {
            $query .= $line;
        }
	}
	fclose($fp);
	unlink(dirname(__FILE__).'/'.$datafilename);
}

echo '正在安装....';
installdata('install_ask.sql');
installdata('install_ask_data.sql');
echo '安装成功.';
unlink(__FILE__);
mysql_close($conn);